using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace RideMe.CommandManagement
{
    public class MenuCommandExecutor : CommandExecutor
    {
        public override void InstanceAdded(object sender, Command command)
        {
            ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
            menuItem.Click += new EventHandler(menuItem_Click);

            base.InstanceAdded(sender, command);
        }

        public override void Enable(object sender, bool setEnabled)
        {
            ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
            menuItem.Enabled = setEnabled;
        }

        public override void Check(object sender, bool setChecked)
        {
            ToolStripMenuItem menuItem = (ToolStripMenuItem)sender;
            menuItem.Checked = setChecked;
        }

        private void menuItem_Click(object sender, EventArgs e)
        {
            Command command = GetCommandForInstance(sender);
            command.DoExecute();
        }
    }
}
